$(function () {
    // 配置路径
    var pageUrl = config.urlAnaConfig.testPath;
    // 登陆
    $(document).keydown(function(event){
        if(event.keyCode==13){
           $(".btn-login").click();
        }
    });
    $(".btn-login").on("click",function () {
        console.log("登陆");
        var userName = $('#loginName').val();
        var userPassword = $('#loginPassword').val();
        $.ajax({
                url: pageUrl+'/api/login/login',
                type: 'POST',
                dataType: 'json',
                data: {
                    'username': userName,
                    'password': userPassword,
                },
                success: function (json) {
                    var msg = '';
                    if (json) {
                        if (json.code === 200) {
                            console.log("success");
                            $(".form-group p").hide();
                            var myToken = json.data.token;
                            console.log(myToken);
                            var userName = json.data.username;
                            function setCookie(name, value, iDay)
                            {
                                var name1 = "userName";
                                var name = "tokenval";
                                var value = myToken;
                                var value1 = userName;
                                var iDay = 10;
                                var oDate = new Date();
                                oDate.setDate(oDate.getDate() + iDay);
                                document.cookie =name+ '=' +encodeURIComponent(value)+ '; expires = '+oDate;
                                document.cookie =name1+ '=' +encodeURIComponent(value1);
                                // console.log(document.cookie)
                            }
                            setCookie();
                           window.location.href="index.html";
                        }else if(json.code === 1013){
                            var errortit = json.msg;
                            console.log(errortit);
                            $(".layer1 .content").html(errortit);
                            $(".layer1").show();
                        }
                    }

                },
                error:  function (XMLHttpRequest, textStatus, errorThrown) {
                    // msg
                    console.log("error");
                    var errorTips = XMLHttpRequest.responseJSON.msg;
                    $(".layer1 .content").html(errorTips);
                    $(".layer1").show();



                }

            });
    })

     // 提示弹框
    $(".layer1 .close1").on("click",function () {
        $(".layer1").hide();
    });
    $(document).click(function(){
    $(".layer1").hide();
    });
    $(".layer1 .main1").click(function(event){
        event.stopPropagation();
    });
    //删除cookie
    function removeCookie(name)
    {
        setCookie(name, 1, -1);
    }
})